﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Chinaer.WCF.Services;
using Chinaer.DTO;

namespace Chinaer.Web
{
    public partial class Country : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Binding();
            }
        }

        protected void btnAddCountry_Click(object sender, EventArgs e)
        {
            if (Session["apiToken"] == null)
            {
                Response.Redirect("login.aspx");
            }
            DTO.CountryDTO countryDTO = new CountryDTO()
            {
                ApiToken = Session["apiToken"].ToString(),
                CountryCode = this.txtCountryCode.Text.Trim(),
                CountryName = this.txtCountryName.Text.Trim(),
                CreateTime = DateTime.Now,
                IsDelete = false,
                IsUse = true
            };
            var result = CommonService.GetChinaerService.AddCountry(countryDTO);
            Response.Write(result);
            Binding();
        }
        private void Binding()
        {
            List<DTO.CountryDTO> listCountry = CommonService.GetChinaerService.GetAllCountry(Session["apiToken"].ToString());
            this.gvList.DataSource = listCountry;
            this.gvList.DataBind();


        }
    }
}